﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;

namespace pptrbt
{
    public class pptgenerator
    {
        // member variables related to ppt generation

        Microsoft.Office.Interop.PowerPoint.Application objApp;
        Presentations objPresSet;
        _Presentation objPres;
        public Slides objSlides;
        public _Slide objSlide;
        public Microsoft.Office.Interop.PowerPoint.Shape objShape;

        public int w, h;


        public void saveppt(string PptFName)
        {
            // Save the presentation.
            objPres.SaveAs(PptFName,
                            PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                            Microsoft.Office.Core.MsoTriState.msoTrue);
        }

        public pptgenerator(string templatefilename)
        {
            objApp = new Microsoft.Office.Interop.PowerPoint.Application();
            objApp.Visible = MsoTriState.msoTrue;
            objPresSet = objApp.Presentations;

            objPres = objPresSet.Open2007(templatefilename, MsoTriState.msoFalse,
                MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);

            objSlides = objPres.Slides;


            //objSlide = objSlides.Add(objSlides.Count + 1, PpSlideLayout.ppLayoutBlank);

            //float w= objSlide.Application.Width;
            //float h = objSlide.Application.Height;
            h = Convert.ToInt16(objPres.PageSetup.SlideHeight);
            w = Convert.ToInt16(objPres.PageSetup.SlideWidth);
            //h=Convert.ToInt16(objSlides.Master.Height);
            //w = Convert.ToInt16(objSlide.Master.Width);

            //objSlide.Application.Height = 100;


            //objShape = objSlide.Shapes.AddLine(100, 200, 150, 250);
            //objShape = objSlide.Shapes.AddLine(100, 200, w-10, h-10);
        }

        public void newslide()
        {
            objSlide = objSlides.Add(objSlides.Count + 1, PpSlideLayout.ppLayoutBlank);

        }

        public void drawtree()
        {
            objSlide = objSlides.Add(objSlides.Count + 1, PpSlideLayout.ppLayoutBlank);
            objShape = objSlide.Shapes.AddLine(100, 200, 150, 250);

        }

        public void newstring(int x, int y, string s)
        {

            objShape = objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, x, y, 600, 100);
            objShape.TextFrame.TextRange.Font.Size = 10;
            objShape.TextFrame.TextRange.Font.Name = "Arial";
            objShape.TextFrame.TextRange.Text = s;

        }

        public void newline(int px, int py, int x, int y)
        {
            objShape = objSlide.Shapes.AddLine(px, py, x, y);
        }

        public void newtable(int x, int y)
        {

            objShape = objSlide.Shapes.AddTable(10, 3, x, y, 100, 20);

        }

        public void newcircle(int x, int y, int r, int c)
        {
            objShape = objSlide.Shapes.AddShape(MsoAutoShapeType.msoShapeOval, x - r / 2, y - r / 2, r, r);
            //objShape.BackgroundStyle=???  // explore it later.
            //objShape.Fill.ForeColor.RGB = System.Drawing.Color.Blue.ToArgb();
           
            int c1;
           
            if (c==pptrbnode.BLACK)
                c1 = (96) + (205 * 255) +   (24 * 65536);
 
            else
            c1=0;

            objShape.Fill.BackColor.RGB = c1;
            //objShape.Fill.BackColor.RGB = Microsoft.Office.Core.MsoThemeColorIndex.msoThemeColorAccent5; //255000000;
        }

        public void newbox(int x, int y, int w, int h)
        {

            objShape = objSlide.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, x, y, w, h);

        }
    }
}
